﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using BearUtil;
using UnityEngine;

/// <summary>
/// 剧情触发节点的数据解析类
/// </summary>
public class StoryDataFormat
{
    [Description("标识")] 
    public string index;
    
    [Description("章节id")]
    public int episode_id;

    [Description("对话id")]
    public int dialogue_id;

    [Description("地图id")]
    public int map_id;

    [Description("触发事件")]
    public int[] trigger_event;

    [Description("触发参数")]
    public int[] trigger_param;

    [Description("镜头位置x坐标")]
    public float camera_pos_x;

    [Description("镜头位置y坐标")]
    public float camera_pos_y;

    [Description("主角位置x坐标")]
    public float pc_pos_x;

    [Description("主角位置y坐标")]
    public float pc_pos_y;

    [Description("主角朝向")]
    public int pc_direction;

    [Description("对话梗概")]
    public string dialogue_gist;

    [Description("备注")]
    public string remark;

    public void SetDialog(DialogNode node, int index)
    {
        try
        {
            episode_id = Convert.ToInt32((node.graph as StoryGraph).basic.id);
            // trigger_param = node.property.trigger_param.Trim().Equals("") ? 0 : Convert.ToInt32(node.property.trigger_param);
            trigger_param = node.property.triggerParams?.ToArray();
            dialogue_id = node.basic.id.Trim().Equals("") ? 0 : Convert.ToInt32(node.basic.id);
        }
        catch (Exception e)
        {
            Debug.LogError("StoryGraph 配置出错, 请检查 Dialog Node 数据");
            Debug.LogError(e);
        }
        
        map_id = node.property.map_id;
        
         List<int> events = new List<int>();
         foreach (var propertyTriggerEvent in node.property.triggerEvents)
             events.Add((int)propertyTriggerEvent);
        
         trigger_event = events.ToArray();
        
         // trigger_event = Convert.ToInt32(node.property.trigger_event);
        
        camera_pos_x = node.property.camera_pos.x;
        camera_pos_y = node.property.camera_pos.y;

        pc_pos_x = node.property.pc_pos.x;
        pc_pos_y = node.property.pc_pos.y;

        pc_direction = (int)node.property.pc_direction;

        dialogue_gist = node.property.dialogue_gist;
        remark = node.property.remark;
    }
}
